package com.jxit0573.android.lib.util;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;

import com.jxit0573.android.lib.activity.BaseActivity;

import java.io.File;

/**
 * @author jia
 */
public class IntentUtils {

    private IntentUtils() {
    }

    public static void go2Dial(Context context, String phoneNum) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri uri = Uri.parse("tel:" + phoneNum);
        intent.setData(uri);
        context.startActivity(intent);
    }

    /**
     * 调用系统录音
     *
     * @param requestCode 请求码
     */
    public static void showRecordSound(BaseActivity activity, int requestCode) {
        Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
        activity.startActivityForResult(intent, requestCode);
    }

    /**
     * 调用系统录像
     *
     * @param requestCode 请求码
     */
    public static void showVideoCapture(BaseActivity activity, int requestCode) {
        Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0.5);
        intent.putExtra(android.provider.MediaStore.EXTRA_SIZE_LIMIT, 768000);
        intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 20);
        File file = new File("/mnt/sdcard/video");
        if (!file.exists()) {
            file.mkdirs();
        }
        File tmpFile = new File("/mnt/sdcard/video/123.mp4");
        Uri outputFileUri = Uri.fromFile(tmpFile);
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        activity.startActivityForResult(intent, requestCode);
//        AssetFileDescriptor videoAsset = getContentResolver().openAssetFileDescriptor(intent.getData(), "r");
//        FileInputStream fis = videoAsset.createInputStream();
//        File tmpFile = new File(Environment.getExternalStorageDirectory(),"VideoFile.3gp");
//        FileOutputStream fos = new FileOutputStream(tmpFile);
//
//        byte[] buf = new byte[1024];
//        int len;
//        while ((len = fis.read(buf)) > 0) {
//            fos.write(buf, 0, len);
//        }
//        fis.close();
//        fos.close();
    }
}
